package com.baizhiedu;

import com.baizhiedu.bean.Customer;
import com.baizhiedu.injection.UserDao;
import com.baizhiedu.injection.UserDaoImpl;
import com.baizhiedu.injection.UserService;
import com.baizhiedu.injection.UserServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
 * ClassName: AppConfig1
 * Description:
 * Date: 2022/12/03 PM 9:37:40
 * <p>
 * project: spring5
 * package: com.baizhiedu
 * email: 1085844536@qq.com
 * version:
 *
 * @author WangGuojian
 */
@Configuration
@PropertySource("classpath:/init.properties")
public class AppConfig1 {

    @Value("${id}")
    private Integer id;

    @Value("${name}")
    private String name;

    @Bean
    public UserDao userDao() {
        return new UserDaoImpl();
    }

    //@Bean
    //public UserService userService(UserDao userDao) {
    //    UserServiceImpl userService = new UserServiceImpl();
    //    userService.setUserDao(userDao);
    //    return userService;
    //}

    /**
     * 简化写法
     *
     * @return {@link UserService}
     */
    @Bean
    public UserService userService() {
        UserServiceImpl userService = new UserServiceImpl();
        userService.setUserDao(userDao());
        return userService;
    }

    @Bean
    public Customer customer() {
        Customer customer = new Customer();
        customer.setId(id);
        customer.setName(name);
        return customer;
    }
}
